import { anyGet, anyPost, anyPut, anyDelete, anyUpload, anyDownload } from './anyRequest'

// 核心 API 管理对象
export const anyApi = {
  // 分页查询
  page: (url: string, params: any) => anyGet(url, params),

  // 列表查询
  list: (url: string, params?: any) => anyGet(url, params),

  // 详情查询
  get: (url: string, id: number | string) => anyGet(`${url}/${id}`),

  // 创建
  add: (url: string, data: any) => anyPost(url, data),

  // 更新
  edit: (url: string, data: any) => anyPut(url, data),
  editById: (url: string, id: number | string, data: any) => anyPut(`${url}/${id}`, data),

  // 删除
  delete: (url: string) => anyDelete(url),
  delById: (url: string, id: number | string) => anyDelete(`${url}/${id}`),
  delBatch: (url: string, ids: (number | string)[]) => anyPost(`${url}/batch-delete`, { ids }),

  // 文件操作
  upload: (url: string, file: File) => anyUpload(url, file),
  download: (url: string, params?: any, filename?: string) => anyDownload(url, params, filename),
  export: (url: string, params?: any, filename?: string) => anyDownload(`${url}/export`, params, filename),
  import: (url: string, file: File) => anyUpload(`${url}/import`, file),

  // 其他操作
  toggleStatus: (url: string, id: number | string, status: boolean | number) => anyPost(`${url}/${id}/status`, { status }),
  sort: (url: string, data: { id: number | string; sort: number }[]) => anyPost(`${url}/sort`, data)
}

export default anyApi